using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;


namespace WtfManager.Framework
{
  ///<summary>
  /// Represents a collection of <see cref="Service">services</see>.
  ///</summary>
  public class ServicesCollection: ObservableCollection<Service>
  {

    ///<summary>
    /// Gets a service by a specified name.
    ///</summary>
    public Service this[string name]
    {
      get
      {
        foreach (Service service in this)
        {
          if (service.Name.Equals(name))
            return service;
        }

        return null;
      }
    }


    ///<summary>
    /// Gets a service by a specified type.
    ///</summary>
    public Service this[Type type]
    {
      get
      {
        foreach (Service service in this)
        {
          if (service.GetType() == type)
            return service;
        }

        return null;
      }
    }


    ///<summary>
    /// Adds a collection of services.
    ///</summary>
    ///<param name="services">A collection of services to add.</param>
    public void AddRange(IEnumerable<Service> services)
    {
      foreach (Service service in services)
        Add(service);
    }
  }
}